package com.training.admin.entity.course;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import com.training.admin.entity.trainer.Trainer;

/**
 * 课程
 * @author Rockett
 *
 */
@Entity
@Table(name = "course")
public class Course {
    
	/**
     * ID
     */
    @Id
    @GeneratedValue
    private Long id;
    
    @Enumerated(EnumType.STRING)
    private CourseCategory category;
   
    /**
     * 课程编号
     */
    private String code;
   
    /**
     * 课程名称
     */
    private String name;
   
    /**
     * 课时
     */
    private Float hour;
  
    /**
     * 课程目标
     */
    private String target;
    
    /**
     * 课程性质
     */
    private String property;
   
    /**
     * 课程类别（管理类/专业通识类）
     */
    private String type;

    /**
     * 讲师
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private Trainer trainer;
    
    @Column(columnDefinition = "longText")
    private String description;
   
    /**
     * 讲授次数
     */
    private int courseTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**讲师评分*/
    private String trainerSurveyResult;
   
    /**课程评分*/
    private String courseSurveyResult;
   
    /**建议*/
    private String surveySuggestion;
    
 
	/**
	 * @return the surveySuggestion
	 */
	public String getSurveySuggestion() {
		return surveySuggestion;
	}

	/**
	 * @param surveySuggestion the surveySuggestion to set
	 */
	public void setSurveySuggestion(String surveySuggestion) {
		this.surveySuggestion = surveySuggestion;
	}

	/**
     * The default constructor
     */
    public Course() {
    }
    
    /**
     * @param trainer
     * @return
     */
    public Course allocateTrainer(Trainer trainer) {
    	this.trainer = trainer;
        this.code = "D"+new Date().getTime();
        return this;
    }
    
    /**
     * 
     * @return
     */
    public Course initliaze() {
    	this.disabled = false;
    	return this;
    }
    
    public Trainer getTrainer() {
		return trainer;
	}

	public void setTrainer(Trainer trainer) {
		this.trainer = trainer;
	}

	/**
     * 
     * @param course
     * @return
     */
    public Course edit(Course course) {
    	this.name = StringUtils.isNotBlank(course.getName()) ? course.getName() : this.name;
    	this.hour = course.getHour();
    	this.target = StringUtils.isNotBlank(course.getTarget()) ? course.getTarget() : this.target;
    	this.description = StringUtils.isNotBlank(course.getDescription()) ? course.getDescription() : this.description;
    	this.courseTime = course.getCourseTime();
    	this.trainer = course.getTrainer();
    	this.property = course.getProperty();
    	this.type = course.getType();
    	return this;
    }
    
    /**
     * @param course
     * @return
     */
    public Course editCourse(Course course) {
        this.name = course.getName();
        this.hour = course.getHour();
        this.description = course.getDescription();
        this.target = course.getTarget();
        this.type = course.getType();
        return this;
    }
    
    public String getStand() {
        if(this.category != null) {
            return this.category.equals(CourseCategory.STAND) ? "是" : "否";
        } else {
            return "是";
        }
    }
    
    public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	/**
     * 
     * @return
     */
    public Course delete() {
    	this.disabled = true;
    	return this;
    }
    
    /**
     * @param name
     */
    public Course(String name) {
        this.id = new Long(1);
        this.name = name;
        this.disabled = false;
    }
    

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }


    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }




	/**
	 * @return the trainerSurveyResult
	 */
	public String getTrainerSurveyResult() {
		return trainerSurveyResult;
	}

	/**
	 * @param trainerSurveyResult the trainerSurveyResult to set
	 */
	public void setTrainerSurveyResult(String trainerSurveyResult) {
		this.trainerSurveyResult = trainerSurveyResult;
	}

	/**
	 * @return the courseSurveyResult
	 */
	public String getCourseSurveyResult() {
		return courseSurveyResult;
	}

	/**
	 * @param courseSurveyResult the courseSurveyResult to set
	 */
	public void setCourseSurveyResult(String courseSurveyResult) {
		this.courseSurveyResult = courseSurveyResult;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}


	/**
	 * @return the hour
	 */
	public Float getHour() {
		return hour;
	}

	/**
	 * @param hour the hour to set
	 */
	public void setHour(Float hour) {
		this.hour = hour;
	}

	/**
	 * @return the target
	 */
	public String getTarget() {
		return target;
	}

	/**
	 * @param target the target to set
	 */
	public void setTarget(String target) {
		this.target = target;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the courseTime
	 */
	public int getCourseTime() {
		return courseTime;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @param courseTime the courseTime to set
	 */
	public void setCourseTime(int courseTime) {
		this.courseTime = courseTime;
	}

	/**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
    public CourseCategory getCategory() {
        return category;
    }
    
    public void setCategory(CourseCategory category) {
        this.category = category;
    }

}